/*
  版权:  @Zach.zhong
  生成日期:2018/2/8   
  说明: T_CustomerReturn_DocNumber表业务层操作类                      
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using CIT.WMS.houseWork.Model;

namespace CIT.WMS.houseWork.Bll
{
    class Bll_T_CustomerReturn_DocNumber
    {
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="strWhere">where条件</param>
        /// <returns></returns>
		public static DataTable Query(string strWhere)
        {
            string sqlcmd = string.Format(@" select K_Doc_Num,D_Doc_Num,CreateTime from T_CustomerReturn_DocNumber {0}", strWhere);
            return Utils.NMS.QueryDataTable(Utils.uContext, sqlcmd, new CIT.WMS.MESWcf.CmdParameter[0]);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public static DataTable QueryDetail(string strWhere)
        {
            string sqlcmd = string.Format(@"select a.K_Doc_Num as '客退单据号',a.D_Doc_Num as '冻结单据号',b.ReelID as 'ReelId',b.MaterialNum as '物料编号',b.Qty as '数量',a.Creator as '客退人',b.CreateTime as '冻结时间',a.CreateTime as '客退时间',b.Remark as '备注'  from dbo.T_CustomerReturn_DocNumber as a
inner join dbo.T_CustomerReturn_Manage as b on a.D_Doc_Num=b.Doc_Number {0}", strWhere);
            return Utils.NMS.QueryDataTable(Utils.uContext, sqlcmd, new CIT.WMS.MESWcf.CmdParameter[0]);
        }
        /// <summary>
        /// 增加
        /// </summary>
        /// <returns></returns>
        public static DataTable Insert(T_CustomerReturn_DocNumber Model)
        {
            string sqlcmd = string.Format(@"
--校验客退单据是否已存在
if not exists(select *  from T_CustomerReturn_DocNumber where K_Doc_Num='{0}')
	begin
		insert into T_CustomerReturn_DocNumber(K_Doc_Num,D_Doc_Num,CreateTime,Creator) values('{0}','{1}',getdate(),'{2}')
		select '1','OK' return
	end
else
	begin
		select '0','客退单据已存在' return
	end", Model.K_Doc_Num, Model.D_Doc_Num, Model.Creator);
            return Utils.NMS.QueryDataTable(Utils.uContext, sqlcmd, new CIT.WMS.MESWcf.CmdParameter[0]);
        }
    }
}
